package vapor.aquila.client.game;

public class TileStatistics
{
	private Terrain m_terrain;
	private boolean m_isMoveCostDivided;
	private int m_foodProductionAdd,
	            m_shieldProductionAdd,
	            m_tradeProductionAdd;
	private float m_foodProductionMultiplier,
	              m_shieldProductionMultiplier,
	              m_tradeProductionMultiplier,
	              m_defenseAdd,
	              m_defenseMultiplier;
	
	public TileStatistics(Terrain terrain)
	{
		m_terrain = terrain;
		
		m_isMoveCostDivided = false;
		m_foodProductionAdd = 0;
		m_shieldProductionAdd = 0;
		m_tradeProductionAdd = 0;
		m_defenseAdd = 0.0f;
		m_foodProductionMultiplier = 1.0f;
		m_shieldProductionMultiplier = 1.0f;
		m_tradeProductionMultiplier = 1.0f;
		m_defenseMultiplier = 1.0f;
	}
	
	/**
	 * Gets the backing terrain that this TileStatistics is serving for.
	 * @return
	 */
	public Terrain getTerrain()
	{
		return m_terrain;
	}
	
	/**
	 * Sets the move cost to be divided.
	 */
	public void setMoveCostDivided() { m_isMoveCostDivided = true; }
	
	//	FOOD	/////////////////////////////////////////////////////////////////////////////////////
	/**
	 * Gets how much this upgrade should add to the food production, before multiplication.  
	 * @return
	 */
	public int getFoodProductionAdd() { return m_foodProductionAdd; }
	
	/**
	 * Gets how much this upgrade should increase the multiplication factor by.  A 0
	 * represents no increase in food production, a 1.0 is a 100% increase (or 200%
	 * of the old total).
	 * @return
	 */
	public float getFoodProductionMultiplier() { return m_foodProductionMultiplier; }
	
	/**
	 * Increases the raw amount of food production for these statistics. 
	 * @param val The amount to increase by
	 */
	public void increaseFoodProductionAdd(int val) { m_foodProductionAdd += val; }
	
	/**
	 * Increases the multiplier of food production for these statistics.
	 * @param val
	 */
	public void increaseFoodProductionMultiplier(float val) { m_foodProductionMultiplier += val; }
	
	//	SHIELDS	/////////////////////////////////////////////////////////////////////////////////////
	public int getShieldProductionAdd() { return m_shieldProductionAdd; }
	
	public float getShieldProductionMultiplier() { return m_shieldProductionMultiplier; }
	
	public void increaseShieldProductionAdd(int val) { m_shieldProductionAdd += val; }
	
	public void increaseShieldProductionMultiplier(float val) { m_shieldProductionMultiplier += val; }
	
	//	TRADE	/////////////////////////////////////////////////////////////////////////////////////
	public int getTradeProductionAdd() { return m_tradeProductionAdd; }
	
	public float getTradeProductionMultiplier() { return m_tradeProductionMultiplier; }
	
	public void increaseTradeProductionAdd(int val) { m_tradeProductionAdd += val; }
	
	public void increaseTradeProductionMultiplier(float val) { m_tradeProductionMultiplier += val; }
	
	//	DEFENSE	/////////////////////////////////////////////////////////////////////////////////////
	public float getDefenseAdd() { return m_defenseAdd; }
	
	public float getDefenseMultiplier() { return m_defenseMultiplier; }
	
	public void increaseDefenseAdd(float val) { m_defenseAdd += val; }
	
	public void increaseDefenseMultiplier(float val) { m_defenseMultiplier += val; }
	
	//	RESULTS	/////////////////////////////////////////////////////////////////////////////////////
	/**
	 * Gets if the amount unit movement costs should be reduced by the game's reducer.
	 * Example: If this is true and the game's reduction factor was 4, then movement over
	 * terrain with this ITerrainUpgrade would be 1/4.
	 * @return If this should be divided.
	 */
	public boolean isMoveCostDivided() { return m_isMoveCostDivided; }
	
	/**
	 * Gets the resulting food production, everything considered.
	 * @return
	 */
	public int getFoodProduction()
	{
		float orig = m_terrain.getFoodProduction();
		float add = getFoodProductionAdd();
		float mul = getFoodProductionMultiplier();
		return performCalculation(orig, add, mul);
	}
	
	/**
	 * Gets the resulting shield production, everything considered.
	 * @return
	 */
	public int getShieldProduction()
	{
		float orig = m_terrain.getShieldProduction();
		float add = getShieldProductionAdd();
		float mul = getShieldProductionMultiplier();
		return performCalculation(orig, add, mul);
	}
	
	/**
	 * Gets the resulting trade production, everything considered.
	 * @return
	 */
	public int getTradeProduction()
	{
		float orig = m_terrain.getTradeProduction();
		float add = getTradeProductionAdd();
		float mul = getShieldProductionMultiplier();
		return performCalculation(orig, add, mul);
	}
	
	/**
	 * Gets the defense multiplier for a defending unit, everything considered
	 * @return
	 */
	public float getDefense()
	{
		float orig = m_terrain.getDefenseMultiplier();
		return performCalculation(orig, getDefenseAdd(), getDefenseMultiplier());
	}
	
	private int performCalculation(float orig, float adder, float multiplier)
	{
		return (int)((orig + adder) * multiplier);
	}
}
